package biz.datalk.industrialland.admin.modules.system.controller;

import biz.datalk.industrialland.admin.modules.system.pojo.dto.SysConfigDTO;
import biz.datalk.industrialland.admin.modules.system.service.ISysConfigService;
import biz.datalk.industrialland.common.encrypt.annotation.RSAES;
import biz.datalk.industrialland.common.json.annotation.Json;
import biz.datalk.industrialland.common.log.aspect.annotation.SysLog;
import biz.datalk.industrialland.common.log.def.OptEnum;
import biz.datalk.industrialland.common.result.UnifyResult;
import biz.datalk.industrialland.common.validated.BatchDelete;
import biz.datalk.industrialland.common.validated.Delete;
import biz.datalk.industrialland.common.validated.Insert;
import biz.datalk.industrialland.common.validated.Update;
import biz.datalk.industrialland.mbg.pojo.po.SysConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tarofang@163.com
 * @date 2019-12-27
 */
@RestController
@RequestMapping("/sys/config")
public class SysConfigController {

    private final ISysConfigService sysConfigService;

    @Autowired
    public SysConfigController(ISysConfigService sysConfigService) {
        this.sysConfigService = sysConfigService;
    }


    @RSAES
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @Json(type = SysConfig.class, filter = "createTime,updateTime,createBy,createName,updateBy,updateName")
    @SysLog(OptEnum.LAND_SYSCFG_11001)
    public UnifyResult list(@RequestBody SysConfigDTO sysConfigDTO) {
        return sysConfigService.list(sysConfigDTO);
    }

    @RSAES
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_SYSCFG_11002)
    public UnifyResult add(@RequestBody @Validated({Insert.class}) SysConfigDTO sysConfigDTO) {
        return sysConfigService.add(sysConfigDTO);
    }

    @RSAES
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_SYSCFG_11003)
    public UnifyResult edit(@RequestBody @Validated({Update.class}) SysConfigDTO sysConfigDTO) {
        return sysConfigService.edit(sysConfigDTO);
    }

    @RSAES
    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_SYSCFG_11004)
    public UnifyResult delete(@RequestBody @Validated({Delete.class}) SysConfigDTO sysConfigDTO) {
        return sysConfigService.delete(sysConfigDTO);
    }

    @RSAES
    @PostMapping(value = "/batchDelete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_SYSCFG_11005)
    public UnifyResult batchDelete(@RequestBody @Validated({BatchDelete.class}) SysConfigDTO sysConfigDTO) {
        return sysConfigService.batchDelete(sysConfigDTO);
    }

    @RSAES
    @PostMapping(value = "/refresh", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_SYSCFG_11006)
    public UnifyResult refresh() {
        return sysConfigService.refresh();
    }
}
